home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / dosdev.arc / DOSDEV.ASM next >
Assembly Source File  |  1985-09-16  |  4KB  |  143 lines

  1. ; Listing 1 - DOSDEV.ASM
  2. ;** PC-DOS Device Driver     (Generalized Skeleton for Character Devices)
  3. ;
  4. ;   Bruce Bordner, 1985
  5. ;
  6. ;
  7. CSEG        SEGMENT PARA PUBLIC 'CODE'
  8. ;
  9. XDV        PROC FAR
  10.         ASSUME CS:CSEG,DS:CSEG,ES:CSEG
  11. BEGIN:
  12. START        EQU $
  13. ;  Header for DOS Device Drivers
  14. NEXT_DEV    DD  -1           ; fake pointer to next device driver
  15. ATTRIBUTE    DW  0C000H     ;character device with IOCTL capability
  16. STRATEGY    DW  XDV_STRAT  ;pointer to function which queues request header
  17. FUNC_CALL    DW  XDV_FUNC   ;pointer to operating functions switch
  18. DEV_NAME    DB  'XDV     ' ;8-byte device name field
  19. ;
  20. ;  Pointer to function request from DOS
  21. RH_OFF        DW  ?     
  22. RH_SEG        DW  ?
  23. ;
  24. ;    Function Address Table for DOS Requests
  25. FUNTAB        LABEL  BYTE
  26.         DW    INIT        ; initialize device
  27.         DW    MEDIA_CHECK    ; do a media check (block dev only)
  28.         DW    BUILD_BPB    ; build BPB          "    "   "
  29.         DW    IOCTL_IN    ; IOCTL input
  30.         DW    INPUT        ; normal input (read device)
  31.         DW    ND_INPUT    ; non-destructive input no wait 
  32.         DW    IN_STAT     ; report input status
  33.         DW    IN_FLUSH    ; flush input
  34.         DW    OUTPUT        ; output (write to device)
  35.         DW    OUT_VERIFY    ; output with verify
  36.         DW    OUT_STAT    ; report output status
  37.         DW    OUT_FLUSH    ; flush output
  38.         DW    IOCTL_OUT    ; IOCTL output
  39. ;
  40. ;
  41. ; Internal Data
  42. ;
  43. ; *end local data
  44. ;
  45. ;
  46. ;
  47. ;  Device Strategy - set pointer to request header from DOS
  48. XDV_STRAT:    MOV  CS:RH_SEG,ES
  49.         MOV  CS:RH_OFF,BX
  50.         RET
  51. ;
  52. ;  Device Interrupt Handler 
  53. XDV_FUNC:    ;preserve machine state
  54.         PUSHF
  55.         CLD
  56.         PUSH  DS
  57.         PUSH  ES
  58.         PUSH  AX
  59.         PUSH  BX
  60.         PUSH  CX
  61.         PUSH  DX
  62.         PUSH  DI
  63.         PUSH  SI
  64. ;      Set DS to CS value
  65.         PUSH  CS
  66.         POP   DS
  67. ;      Load ES and BX with RH_SEG and RH_OFF
  68.         LES   BX,DWORD PTR CS:RH_OFF
  69. ;      Branch to correct function in FUNTAB based on function code from DOS
  70.         MOV   AL,ES:[BX+2]    ; get function code byte
  71.         XOR   AH,AH
  72.         SHL   AL,1        ; make it into offset into FUNTAB
  73.         LEA   DI,FUNTAB     ; get address of FUNTAB base
  74.         ADD   DI,AX
  75.         JMP   WORD PTR[DI]    ; jump to function code
  76. ;
  77. ;
  78. ;
  79. ;  Device Initialization
  80. INIT:        MOV  DX,OFFSET LASTWORD      ;end offset of XDV
  81.         MOV  ES:[BX+14],DX
  82.         MOV  ES:[BX+16],CS       ; and segment into request hdr 
  83.         MOV  WORD PTR ES:[BX+3],0100H ;set status word to DONE, NOERROR
  84.         JMP  EXIT
  85. ;
  86. ;
  87. ;   Functions not supported:
  88. ;
  89. MEDIA_CHECK:
  90. BUILD_BPB:    
  91. IOCTL_IN:    
  92. ND_INPUT:    
  93. IN_STAT:    
  94. IN_FLUSH:    
  95. OUT_VERIFY:    
  96. OUT_STAT:
  97. OUT_FLUSH:
  98. IOCTL_OUT:
  99.         MOV ES:WORD PTR [BX+3],0100H  ; set status DONE, NOERROR
  100.         JMP EXIT
  101. ;************************************************************ 
  102. ; ES:[BX]+14 = offset of buffer in calling program
  103. ; ES:[BX]+16 = segment of buffer
  104. ; ES:[BX]+18 = number of bytes to transfer in this call 
  105. ;        (NOTE: DOS 2 requests one byte per call)
  106. ;
  107. INPUT: 
  108. ;
  109.         MOV  WORD PTR ES:[BX+3],0100H  ; set DONE, NOERROR
  110.         JMP  EXIT
  111. ;************************************************************* 
  112. ; ES:[BX]+14 = offset of buffer in calling program
  113. ; ES:[BX]+16 = segment of buffer
  114. ; ES:[BX]+18 = number of bytes to transfer in this call 
  115. ;        (NOTE: DOS 2 requests one byte per call)
  116. ;                    
  117. OUTPUT:
  118.         MOV  WORD PTR ES:[BX+3],0100H  ; set DONE, NOERROR
  119.         JMP  EXIT 
  120. ;*********************************************************
  121. ;
  122. ;  Restore registers and exit
  123. EXIT:        POP  SI
  124.         POP  DI
  125.         POP  DX
  126.         POP  CX
  127.         POP  BX
  128.         POP  AX
  129.         POP  ES          
  130.         POP  DS
  131.         POPF
  132.         RET
  133. ;
  134. LASTWORD    EQU $          ;end of XDV - used for terminate & stay resident
  135. XDV        ENDP
  136. CSEG        ENDS
  137.         END  BEGIN
  138. 
  139.         POPF
  140.         RET
  141. ;
  142. LASTWORD    EQU $          ;end of XDV - used for terminate & stay resident
  143.